home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.02 Feb 96 / Adding Scripts to Menus / Script Menu test project / Powering Up Code / SCPage.cp < prev    next >
Encoding:
Text File  |  1995-06-15  |  2.3 KB  |  108 lines  |  [TEXT/MMCC]

  1. // ===========================================================================
  2. // SCPage.cp -- the page class 
  3. // ===========================================================================
  4. // © 1995 James Kaput, Jeremy Roschelle SimCalc Project
  5.  
  6. #include "SCPage.h"
  7. #include "SCDoc.h"
  8. #include "SCApp.h"
  9. #include "SCModelProperty.h"
  10.  
  11. SCPage::SCPage(SCDoc *inDoc)
  12. {
  13.     mModelKind = modelKind;
  14.     mSuperModel = inDoc;
  15.     inDoc->AddSubModel(this); // stores the page a list in the document
  16.     mID = SCApp::GenerateUniqueID();
  17.     *mName = 0;
  18. }
  19.  
  20. SCPage::~SCPage()
  21. {
  22.     mSuperModel->RemoveSubModel(this);
  23.     mSuperModel = nil; // prevents LModelObject from doing removal
  24. }
  25.  
  26. void    
  27. SCPage::GetDescriptor(Str255 outName) const
  28. {
  29.     CopyPStr(mName,outName);
  30. }
  31.  
  32. Int32     
  33. SCPage::GetID() const
  34. {
  35.     return mID;
  36. }
  37.  
  38. LModelObject*    
  39. SCPage::GetModelProperty(DescType inProperty) const
  40. {
  41.     return new SCModelProperty(inProperty, (SCPage *)this);
  42. }
  43.  
  44. void    
  45. SCPage::HandleAppleEvent(const AppleEvent    &inAppleEvent,
  46.                     AppleEvent            &outAEReply,
  47.                     AEDesc                &outResult,
  48.                     Int32                inAENumber)
  49. {
  50.     switch (inAENumber) {
  51.         case ae_Select:
  52.             ((SCDoc *)mSuperModel)->SetSelection(this);
  53.             break;
  54.         default:
  55.             inherited::HandleAppleEvent(inAppleEvent,outAEReply,outResult,inAENumber);
  56.     }
  57. }
  58.  
  59. void    
  60. SCPage::GetAEProperty(
  61.                     DescType        inProperty,
  62.                     const AEDesc    &inRequestedType,
  63.                     AEDesc            &outPropertyDesc) const
  64. {
  65.     long        id, index;
  66.     Str255    name;
  67.     
  68.     switch (inProperty) {
  69.         case pIndex:
  70.             index = mSuperModel->GetPositionOfSubModel(SCPage::modelKind, this); 
  71.             FailOSErr_(AECreateDesc(typeLongInteger, (Ptr) &index,
  72.                         sizeof(long), &outPropertyDesc));
  73.             break;
  74.         case 'ID  ':
  75.             id = GetID();
  76.             FailOSErr_(AECreateDesc(typeLongInteger, (Ptr) &id,
  77.                         sizeof(long), &outPropertyDesc));
  78.             break;
  79.         case pName:
  80.             GetDescriptor(name);
  81.             FailOSErr_(AECreateDesc(typeChar, &(name[1]),
  82.                         name[0], &outPropertyDesc));
  83.             break;
  84.         default:
  85.             inherited::GetAEProperty(inProperty,inRequestedType,outPropertyDesc);
  86.     }
  87.  
  88. }
  89.  
  90. void    
  91. SCPage::SetAEProperty(
  92.                     DescType        inProperty,
  93.                     const AEDesc    &inValue,
  94.                     AEDesc        &outAEReply)
  95. {
  96.     Str255    name;
  97.     
  98.     switch (inProperty) {            
  99.         case pName:
  100.             UExtractFromAEDesc::ThePString(inValue,name);
  101.             CopyPStr(name,mName);
  102.             break;
  103.         default:
  104.             inherited::SetAEProperty(inProperty,inValue,outAEReply);
  105.     }
  106.  
  107. }
  108.